<html>
<head><meta charset="utf-8"><title>stacked-borrows · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html">stacked-borrows</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="131160660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131160660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131160660">(Aug 09 2018 at 09:31)</a>:</h4>
<p>An interesting question: <a href="https://www.reddit.com/r/rust/comments/95f4xi/stacked_borrows_an_aliasing_model_for_rust/e3u0749/?context=3" target="_blank" title="https://www.reddit.com/r/rust/comments/95f4xi/stacked_borrows_an_aliasing_model_for_rust/e3u0749/?context=3">https://www.reddit.com/r/rust/comments/95f4xi/stacked_borrows_an_aliasing_model_for_rust/e3u0749/?context=3</a></p>



<a name="131160670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131160670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131160670">(Aug 09 2018 at 09:31)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> are there still plans to change MIR to not allow "nested path expressions" like <code>a.b.c.d</code> or <code>(*a.f).f2</code>?</p>



<a name="131162057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131162057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131162057">(Aug 09 2018 at 10:03)</a>:</h4>
<p>vague plans, yes</p>



<a name="131162058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131162058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131162058">(Aug 09 2018 at 10:03)</a>:</h4>
<p>no action has been taken</p>



<a name="131162292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131162292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131162292">(Aug 09 2018 at 10:09)</a>:</h4>
<p>At least when it comes to nested fields, I am not convinced any more that we want that. would still be nice to have for deref, though.</p>



<a name="131162354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131162354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131162354">(Aug 09 2018 at 10:10)</a>:</h4>
<p>or at least, <em>if</em> we do this even for field accesses, that should probably mean that when accessing <code>t.b</code> we actually activate all of <code>t</code></p>



<a name="131162465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131162465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131162465">(Aug 09 2018 at 10:13)</a>:</h4>
<p>I envision these being a special sort of operation -- sort of like <code>GEP</code> in LLVM -- that ends with some kind of "bless" operation</p>



<a name="131162477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131162477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131162477">(Aug 09 2018 at 10:13)</a>:</h4>
<p>that indicates the final path the user wrote</p>



<a name="131162481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131162481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131162481">(Aug 09 2018 at 10:13)</a>:</h4>
<p>it seems like that would be important to the borrowck</p>



<a name="131162484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131162484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131162484">(Aug 09 2018 at 10:13)</a>:</h4>
<p>in particular we need to be able to permit access to disjoint fields</p>



<a name="131162534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131162534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131162534">(Aug 09 2018 at 10:14)</a>:</h4>
<p>e.g.</p>
<div class="codehilite"><pre><span></span><span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="p">(</span><span class="kt">u32</span><span class="p">,</span><span class="w"> </span><span class="kt">u32</span><span class="p">);</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">x</span><span class="p">).</span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">x</span><span class="p">).</span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
</pre></div>



<a name="131162909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131162909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131162909">(Aug 09 2018 at 10:22)</a>:</h4>
<p>hm, yeah</p>



<a name="131162938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131162938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131162938">(Aug 09 2018 at 10:23)</a>:</h4>
<p>so point is I could imagine that the "GEP" part of it somehow has less validation?</p>



<a name="131162998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131162998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131162998">(Aug 09 2018 at 10:24)</a>:</h4>
<p>that was an interesting question though (the one from reddit)</p>



<a name="131163008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131163008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131163008">(Aug 09 2018 at 10:24)</a>:</h4>
<p>I feel like the "tagging" question also comes into play?</p>



<a name="131163020"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131163020" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131163020">(Aug 09 2018 at 10:25)</a>:</h4>
<p>e.g., does <code>let t = &amp;*s;</code> retag the data in <code>s</code>? oh, well, I guess there are no <em>references</em> in there</p>



<a name="131163299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131163299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131163299">(Aug 09 2018 at 10:31)</a>:</h4>
<p>no this doesn't load anything from memory, no retagging</p>



<a name="131163304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131163304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131163304">(Aug 09 2018 at 10:31)</a>:</h4>
<p>but of course a new ref is created, which gets a fresh tag</p>



<a name="131163613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/131163613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#131163613">(Aug 09 2018 at 10:38)</a>:</h4>
<p>I see</p>



<a name="132073494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/132073494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#132073494">(Aug 13 2018 at 21:36)</a>:</h4>
<p><span class="user-mention" data-user-id="123893">@alercah</span> </p>
<div class="codehilite"><pre><span></span><span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">split_at_mut</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">mid</span>: <span class="kt">usize</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="p">[</span><span class="n">T</span><span class="p">],</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="p">[</span><span class="n">T</span><span class="p">])</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">len</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">len</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">ptr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">as_mut_ptr</span><span class="p">();</span><span class="w"> </span><span class="c1">// here a Raw gets pushed onto the stack for the entire slice</span>

<span class="w">        </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">assert</span><span class="o">!</span><span class="p">(</span><span class="n">mid</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">len</span><span class="p">);</span><span class="w"></span>

<span class="w">            </span><span class="p">(</span><span class="n">from_raw_parts_mut</span><span class="p">(</span><span class="n">ptr</span><span class="p">,</span><span class="w"> </span><span class="n">mid</span><span class="p">),</span><span class="w"> </span><span class="c1">// now the first half of the slice has a new Uniq pushed</span>
<span class="w">             </span><span class="n">from_raw_parts_mut</span><span class="p">(</span><span class="n">ptr</span><span class="p">.</span><span class="n">offset</span><span class="p">(</span><span class="n">mid</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">isize</span><span class="p">),</span><span class="w"> </span><span class="n">len</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">mid</span><span class="p">))</span><span class="w"> </span><span class="c1">// and now the second part follows suit</span>
<span class="w">           </span><span class="c1">// using `self` again here would be possible, but that would invalidate the two `from_raw_parts`! I.e., if you returned</span>
<span class="w">           </span><span class="c1">// them (which activates references), that would be UB. But since `self` is not used again, this code is fine.</span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</pre></div>



<a name="132077047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/132077047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#132077047">(Aug 13 2018 at 23:01)</a>:</h4>
<p><span class="user-mention" data-user-id="123893">@alercah</span> (if you click my message before replying, your reply should go to the right topic. we should try not to be too much off-topic in the exhaustiveness discussion.)<br>
How would it create the subslices without calling <code>from_raw_parts_mut</code>?</p>



<a name="132511994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/132511994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> alercah <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#132511994">(Aug 21 2018 at 11:29)</a>:</h4>
<p>Ah, I forgot I replied to this but I didn't. It would require different aliasing rules.</p>



<a name="135972009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135972009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135972009">(Oct 17 2018 at 13:19)</a>:</h4>
<p>Got a first implementation of stacked borrows (without barriers or retagging). That went much smoother than I expected :D</p>



<a name="135972077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135972077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135972077">(Oct 17 2018 at 13:20)</a>:</h4>
<p>"implementation" in... what?</p>



<a name="135972357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135972357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135972357">(Oct 17 2018 at 13:25)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> in miri</p>



<a name="135972365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135972365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135972365">(Oct 17 2018 at 13:25)</a>:</h4>
<p>ah dang, not seeing some of the errors I was expecting though</p>



<a name="135972369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135972369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135972369">(Oct 17 2018 at 13:25)</a>:</h4>
<p>something is not being tracked enough</p>



<a name="135972724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135972724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135972724">(Oct 17 2018 at 13:30)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> </p>
<blockquote>
<p>ps is there stacked borrow code I can review?</p>
</blockquote>
<p><a href="https://github.com/RalfJung/miri/commits/stacked-borrows" target="_blank" title="https://github.com/RalfJung/miri/commits/stacked-borrows">https://github.com/RalfJung/miri/commits/stacked-borrows</a></p>



<a name="135972739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135972739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135972739">(Oct 17 2018 at 13:30)</a>:</h4>
<p>and <a href="https://github.com/rust-lang/rust/pull/55125" target="_blank" title="https://github.com/rust-lang/rust/pull/55125">https://github.com/rust-lang/rust/pull/55125</a></p>



<a name="135973166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973166">(Oct 17 2018 at 13:37)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> &lt;3 thanks!</p>



<a name="135973209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973209">(Oct 17 2018 at 13:38)</a>:</h4>
<p>ah dang... we optimize away <code>&amp;*x</code> to just <code>x</code> even when they don't have the same type, I forgot about that</p>



<a name="135973210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973210">(Oct 17 2018 at 13:38)</a>:</h4>
<p>are those overlapping?</p>



<a name="135973217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973217">(Oct 17 2018 at 13:38)</a>:</h4>
<p>that is, if I review <a href="https://github.com/rust-lang/rust/issues/55125" target="_blank" title="https://github.com/rust-lang/rust/issues/55125">#55125</a>, does that  suffice?</p>



<a name="135973221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973221">(Oct 17 2018 at 13:38)</a>:</h4>
<p>namely we do that even when <code>x</code> is a mutable ref and we are turning it into a shared ref</p>



<a name="135973223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973223">(Oct 17 2018 at 13:38)</a>:</h4>
<p>so there is no <code>Ref</code> left for me to hook...</p>



<a name="135973225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973225">(Oct 17 2018 at 13:38)</a>:</h4>
<p>interesting</p>



<a name="135973230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973230">(Oct 17 2018 at 13:38)</a>:</h4>
<p>I knew that. and forgot.^^</p>



<a name="135973241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973241">(Oct 17 2018 at 13:38)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> one is the rustc changes and the other is the miri changes. no overlap.</p>



<a name="135973278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973278">(Oct 17 2018 at 13:39)</a>:</h4>
<p>dang that makes things much harder</p>



<a name="135973289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973289">(Oct 17 2018 at 13:39)</a>:</h4>
<p>basically we are transmuting <code>&amp;mut</code> to <code>&amp;</code> all the time, even if the original source didn't</p>



<a name="135973442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973442">(Oct 17 2018 at 13:42)</a>:</h4>
<p>I think it's "ok" to remove that, or at least only do it if validation is disabled or something.. but I guess that's annoying because libstd?</p>



<a name="135973518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973518">(Oct 17 2018 at 13:43)</a>:</h4>
<p>that is, it is not clearly a "valid" optimization for us to be doing</p>



<a name="135973536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973536">(Oct 17 2018 at 13:43)</a>:</h4>
<p>well depends. people have been asking for more details on transmutes anyway</p>



<a name="135973607"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973607" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973607">(Oct 17 2018 at 13:44)</a>:</h4>
<p>I just hoped I could get a basic model working that just looks at <code>&amp;</code>, <code>*</code>, casts and memory accesses</p>



<a name="135973617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973617">(Oct 17 2018 at 13:44)</a>:</h4>
<p>no retagging, no recursing over the types</p>



<a name="135973653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973653">(Oct 17 2018 at 13:45)</a>:</h4>
<p>and, well, it works with <code>-Zmir-opt-level=0</code>^^</p>



<a name="135973654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973654">(Oct 17 2018 at 13:45)</a>:</h4>
<blockquote>
<p>well depends. people have been asking for more details on transmutes anyway</p>
</blockquote>
<p>confirm</p>



<a name="135973665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973665">(Oct 17 2018 at 13:45)</a>:</h4>
<p>I guess if transmutes are "silent"</p>



<a name="135973675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973675">(Oct 17 2018 at 13:45)</a>:</h4>
<p>what should I confirm?</p>



<a name="135973681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973681">(Oct 17 2018 at 13:45)</a>:</h4>
<p>sorry, that means "I agree, you are correct" :)</p>



<a name="135973727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135973727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135973727">(Oct 17 2018 at 13:46)</a>:</h4>
<p>oh. I thought it was an imperative. ^^</p>



<a name="135974472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135974472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135974472">(Oct 17 2018 at 13:59)</a>:</h4>
<p>well back on topic though, I'll work with mir-opt-level=0 for now</p>



<a name="135974529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135974529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135974529">(Oct 17 2018 at 14:00)</a>:</h4>
<p>retagging is annoying because it has to happen after <em>every</em>... well not sure after every what. every assignment, likely? plus fn calls and return?</p>



<a name="135974535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135974535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135974535">(Oct 17 2018 at 14:00)</a>:</h4>
<p>it has some logic that's similar to validation</p>



<a name="135974549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135974549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135974549">(Oct 17 2018 at 14:00)</a>:</h4>
<p>but unlike validation it needs to be able to actually mutate stuff, validation works on operands that you cannot mutate</p>



<a name="135974571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135974571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135974571">(Oct 17 2018 at 14:01)</a>:</h4>
<p>so all in all, not nice</p>



<a name="135974585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135974585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135974585">(Oct 17 2018 at 14:01)</a>:</h4>
<p>oh wait someone siwtched the topic</p>



<a name="135974587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135974587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135974587">(Oct 17 2018 at 14:01)</a>:</h4>
<p>when did that happen^^</p>



<a name="135974588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135974588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135974588">(Oct 17 2018 at 14:01)</a>:</h4>
<p>heh that was me :P</p>



<a name="135974595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135974595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135974595">(Oct 17 2018 at 14:01)</a>:</h4>
<p>you can change it back quite easily</p>



<a name="135974641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135974641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135974641">(Oct 17 2018 at 14:02)</a>:</h4>
<p>for just my msgs?</p>



<a name="135974644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135974644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135974644">(Oct 17 2018 at 14:02)</a>:</h4>
<p>just click the "edit" next to your msg</p>



<a name="135974646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135974646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135974646">(Oct 17 2018 at 14:02)</a>:</h4>
<p>and you can select "this message and all ones after it"</p>



<a name="135974647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135974647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135974647">(Oct 17 2018 at 14:02)</a>:</h4>
<p>yes</p>



<a name="135974669"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135974669" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135974669">(Oct 17 2018 at 14:02)</a>:</h4>
<p>wow technology</p>



<a name="135974673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/135974673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#135974673">(Oct 17 2018 at 14:02)</a>:</h4>
<p>no autocompletion for the topic name though</p>



<a name="136108441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136108441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136108441">(Oct 19 2018 at 12:43)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> I just realized (seems rather obvious now) that optimizing away <code>x as *const _</code> to just a transmute is not legal. we do want to rule out using raw ptrs to access locations that never got "leaked" by being cast to raw. So I will assume that such optimizations don't happen. (I think currently they don't, but who knows which ideas people have.)</p>



<a name="136108499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136108499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136108499">(Oct 19 2018 at 12:44)</a>:</h4>
<p>that leaves optimizing away <code>&amp;[mut] *x</code>, where <code>x</code> might be a ref or a raw ptr -- but at least the output of the transmutes we want to support are restricted to references.</p>



<a name="136108557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136108557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136108557">(Oct 19 2018 at 12:45)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> makes sense</p>



<a name="136115834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136115834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136115834">(Oct 19 2018 at 14:45)</a>:</h4>
<p>also, at least the way I have implemented this now, <code>&amp;mut</code>'s validaity invariant actually says that the tag must be a <code>Uniq</code>. everything else is insta-UB. That makes some things simpler...</p>



<a name="136116616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136116616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136116616">(Oct 19 2018 at 14:57)</a>:</h4>
<p>actually it can also be a <code>Raw</code>, which pretty much behaves like a raw ref... it's not <em>really</em> unique. but that seems okay; for unique refs we didnt retag we also cannot know if their tag is <em>really</em> unique.</p>



<a name="136116626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136116626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136116626">(Oct 19 2018 at 14:57)</a>:</h4>
<p>an <code>&amp;mut</code> with a <code>Frz</code> tag however is insta-UB, for now.</p>



<a name="136123389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136123389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136123389">(Oct 19 2018 at 16:42)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> I have a rather surprising case: <a href="https://github.com/RalfJung/miri/blob/stacked-borrows/tests/compile-fail/stacked_borrows/illegal_write4.rs" target="_blank" title="https://github.com/RalfJung/miri/blob/stacked-borrows/tests/compile-fail/stacked_borrows/illegal_write4.rs">https://github.com/RalfJung/miri/blob/stacked-borrows/tests/compile-fail/stacked_borrows/illegal_write4.rs</a><br>
I really want this to fail earlier, but cannot find a way to make that happen without breaking code we probably want to allow.</p>



<a name="136277228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136277228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136277228">(Oct 22 2018 at 16:11)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> here's another interesting problem: Doing <code>&amp;slice[0] as *const _</code> only leaks the first element of the slice to a raw pointer, so you cannot access the other elements even after you did that...</p>



<a name="136277777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136277777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136277777">(Oct 22 2018 at 16:21)</a>:</h4>
<p>oh, that's an interesting reason to prefer <code>as_ptr</code></p>



<a name="136278162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136278162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136278162">(Oct 22 2018 at 16:27)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> regarding your first example: do you have a sense of where you <em>want</em> it to fail? It seems like pursuing <code>transmute</code> is having the effect that <em>creating references</em> becomes far less significant until they are used...does that seem accurate?</p>



<a name="136278786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136278786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136278786">(Oct 22 2018 at 16:36)</a>:</h4>
<blockquote>
<p>oh, that's an interesting reason to prefer <code>as_ptr</code></p>
</blockquote>
<p>only that <code>as_ptr</code> would be to be a primitive MIR operation to make this actually work</p>



<a name="136279037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136279037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136279037">(Oct 22 2018 at 16:41)</a>:</h4>
<blockquote>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> regarding your first example: do you have a sense of where you <em>want</em> it to fail? It seems like pursuing <code>transmute</code> is having the effect that <em>creating references</em> becomes far less significant until they are used...does that seem accurate?</p>
</blockquote>
<p>I had hoped that and use of an <code>&amp;mut</code> would give you basically that it is still exercising its exclusive access. And we could maybe still get there but we'd have to say that a non-exclusively-reborrowed <code>&amp;mut T</code> is allowed to point only to memory with its tag being the top of the stack, <em>ignoring freezing and barriers</em>. Currently, we check if it is anywhere on the stack, i.e., we check if reactivating it would be possible at all.</p>



<a name="136279212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136279212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136279212">(Oct 22 2018 at 16:44)</a>:</h4>
<blockquote>
<p>only that as_ptr would be to be a primitive MIR operation to make this actually work</p>
</blockquote>
<p>Not necessarily - <code>&amp;[T] as *const [T] as *const T</code> should work.</p>



<a name="136279297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136279297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136279297">(Oct 22 2018 at 16:44)</a>:</h4>
<p>actually what I said above is wrong, we have to also allow an <code>&amp;mut</code> pointing to sth that is currently raw because if there is interior mutability, that#s what happens</p>



<a name="136279304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136279304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136279304">(Oct 22 2018 at 16:44)</a>:</h4>
<p><span class="user-mention" data-user-id="125253">@Nicole Mazzuca</span> good point! I'll try that immediately.</p>



<a name="136279722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136279722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136279722">(Oct 22 2018 at 16:51)</a>:</h4>
<p><span class="user-mention" data-user-id="125253">@Nicole Mazzuca</span> this actually works :-)</p>



<a name="136281088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows/near/136281088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/stacked-borrows.html#136281088">(Oct 22 2018 at 17:14)</a>:</h4>
<p>good! I'd hope so :P</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>